<%--
  Created by IntelliJ IDEA.
  User: 曹梦1
  Date: 2024/10/27
  Time: 17:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <script src="/js/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body>
<div id="app">
    <el-form :inline="true" :model="searchBranch" class="demo-form-inline">
        <el-form-item label="分店信息">
            <el-select v-model="searchBranch.branchid" placeholder="请选择分店" clearable>
                <el-option
                        v-for="item in branchList"
                        :label="item.branchname"
                        :value="item.branchid">
                </el-option>
            </el-select>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="onaudit">查询</el-button>
        </el-form-item>
    </el-form>
    <el-button type="primary" @click="onrefresh">刷新</el-button>

    <%-- 展示列表--%>
    <el-table
            :data="intlibrarys"
            :border="true"
            style="width: 100%">
        <el-table-column
                prop="id"
                label="入库编号"
                width="100"
        >
        </el-table-column>
        <el-table-column
                prop="date"
                label="入库时间"
                width="180"
        >
        </el-table-column>
        <el-table-column
                prop="status"
                label="审核状态"
        >
            <template slot-scope="scope">
                <%--if判断1为审核中，2为审核通过，3为不通过--%>
                <el-tag
                        v-if="scope.row.status==1"
                        type="warning"
                        effect="dark">
                    审核中
                </el-tag>
                <el-tag
                        v-else-if="scope.row.status==2"
                        type="success"
                        effect="dark">
                    审核通过
                </el-tag>
                <el-tag
                        v-else-if="scope.row.status==3"
                        type="danger"
                        effect="dark">
                    审核不通过
                </el-tag>
            </template>
        </el-table-column>
        <el-table-column
                prop="staff.staffname"
                label="操作员"
                width="100"
        >
        </el-table-column>
        <el-table-column
                prop="branch.branchname"
                label="店名"
                width="150"
        >
        </el-table-column>
        <el-table-column
                prop="dates"
                label="审核时间"
                width="180"
        >
        </el-table-column>
        <el-table-column
                fixed="right"
                label="详情"
                width="150px"
        >
            <template slot-scope="scope">
                <el-button type="info" @click="handleClick(scope.row.id)">详细信息</el-button>
            </template>
        </el-table-column>
        <el-table-column
                fixed="right"
                label="操作"
                width="250px"
        >
            <template slot-scope="scope" v-if="scope.row.status==1">
                    <el-button type="success" @click="Approved(scope.row.id)">审核通过</el-button>
                    <el-button type="danger" @click="Reject(scope.row.id)">审核驳回</el-button>
            </template>
        </el-table-column>
    </el-table>
    <%--分页 --%>
    <el-pagination
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"
            :current-page="currentPage"
            :page-sizes="[10, 15, 25, 35]"
            :page-size="pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total">
    </el-pagination>

    <%--回显详细信息--%>
    <el-dialog title="详细信息" :visible.sync="dialogFormVisible2" width="100%">
        <el-table
                :data="goodForm"
                :border="true"
                style="width: 100%">
            <el-table-column
                    prop="id"
                    label="入库编号" >
            </el-table-column>
            <el-table-column
                    prop="goodsid"
                    label="商品编号" >
            </el-table-column>
            <el-table-column
                    prop="goods.goodsname"
                    label="商品名称"
            >
            </el-table-column>
            <el-table-column
                    prop="num"
                    label="库存"
            >
            </el-table-column>
            <el-table-column
                    prop="goods.cprice"
                    label="进价"
            >
            </el-table-column>
            <el-table-column
                    prop="branch.branchname"
                    label="店名"
            >
            </el-table-column>
            <el-table-column
                    label="总价"
            >
                <template slot-scope="scope">
                    <span>{{scope.row.num * scope.row.goods.cprice}}</span>
                </template>
            </el-table-column>
        </el-table>
    </el-dialog>
    <%--结束详细信息--%>

</div>
</body>
<script>
    let app = new Vue({
        el: '#app',
        data: {
            searchBranch: {},//查询条件
            branchList: [],//分店列表
            intlibrarys: [],//入库列表
            currentPage: 1,//当前页码
            pageSize: 10,//每页显示的条数
            total: 0,//总条数

            dialogFormVisible2:false,//详细信息弹框
            goodForm:undefined,//详情信息商品信息列表

            userbranchid:undefined,//当前用户分店id
            auditid:undefined, //要审核的id

        },
        created() {//页面加载完就执行
            this.loadbranchList(); //加载分店列表
            this.loadIntlibrary();//加载入库列表
            this.loadbranchid();//获取当前用户分店id
        },
        methods: {
            //获取当前用户分店id
            loadbranchid(){
                axios.get("/intlibrary/getbranchid").then(resp=>{
                    this.userbranchid=resp.data.data;
                })
            },
            //审核通过 状态为2
            Approved(id){
                this.$confirm('此操作是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.get("/intlibrary/getBranchByid?id="+id).then(resp=>{
                        if (resp.data.code === 200) {
                            this.auditid = resp.data.data;

                        }
                        //判断要审核的分店名称与当前登录者的分店名称是否一致
                        if (this.userbranchid != this.auditid) {
                            this.$message({
                                message: '当前登录者与要审核的分店名称不一致，无法审核',
                                type: 'warning'
                            });
                            return;
                        }
                    axios.post("/intlibrary/approved?id="+id).then(resp=>{
                        if(resp.data.code==200){
                            this.$message({
                                type: 'success',
                                message: '审核通过!'
                            });
                            this.loadIntlibrary();
                        }else{
                            this.$message({
                                type: 'error',
                                message: '审核失败!'
                            });
                        }
                    })
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消'
                    });
                });

            },
            //审核驳回
            Reject(id){
                this.$prompt('请输入理由', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                }).then(({ value }) => {
                        axios.get("/intlibrary/getBranchByid?id="+id).then(resp=> {
                            if (resp.data.code === 200) {
                                this.auditid = resp.data.data;
                            }
                            //判断要审核的分店名称与当前登录者的分店名称是否一致
                            if (this.userbranchid != this.auditid) {
                                this.$message({
                                    message: '当前登录者与要审核的分店名称不一致，无法审核',
                                    type: 'warning'
                                });
                                return;
                            }
                            axios.post("/intlibrary/reject?id=" + id + "&remark=" + value).then(resp => {
                                if (resp.data.code == 200) {
                                    this.$message({
                                        type: 'success',
                                        message: '驳回成功!'
                                    });
                                    this.loadIntlibrary();
                                } else {
                                    this.$message({
                                        type: 'error',
                                        message: '审核失败!'
                                    });
                                }
                            })
                        })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '取消输入'
                    });
                });


            },
            //详情信息
            handleClick(id){
                this.dialogFormVisible2=true;
                axios.get("/storageVolume/getStorageVolume?id="+id).then(resp=>{
                    this.goodForm=resp.data.data;
                })
            },

            //加载入库信息
            loadIntlibrary() {
                axios.post("/intlibrary/getAllInLib?pageNum=" + this.currentPage + "&pageSize=" + this.pageSize, this.searchBranch).then(resp => {
                    this.intlibrarys = resp.data.data.list;
                    this.total = resp.data.data.total;
                })
            },
            //分页
            //改变每页显示的条数
            handleSizeChange1(val) {
                this.pageSize = val;
                this.loadIntlibrary();
            },
            //改变当前页码
            handleCurrentChange1(val) {
                this.currentPage = val;
                this.loadIntlibrary();
            },
            //加载分店列表
            loadbranchList() {
                axios.get("/branch/getBranchName").then(resp => {
                    this.branchList = resp.data.data;
                })
            },
            //查询
            onaudit() {
                this.loadIntlibrary();
            },
            //刷新
            onrefresh() {
                this.searchBranch = {};
                this.loadIntlibrary();
            }
        }
    })
</script>
</html>
